From a237f778b05854eca7cb6c6f84cdf26650e0df92 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sun, 8 Dec 2013 15:39:25 +0100 Subject: [PATCH] SpecialWantedcategories: Show more current information when in cached mode Usability improvements I thought up when trying to through nearly 500 entries on this page on pl.wp. * Strike items on the list if the category was created or emptied since the last update * Show current number of items if it's different from the original one Change-Id: Ifcc534f19fb60732bcd40f75ddca390106ebe28e --- includes/specials/SpecialWantedcategories.php | 60 +++++++++++++++++-- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 1 + maintenance/language/messages.inc | 1 + 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/includes/specials/SpecialWantedcategories.php b/includes/specials/SpecialWantedcategories.php index d2ffdb9402..c8ba4acb07 100644 --- a/includes/specials/SpecialWantedcategories.php +++ b/includes/specials/SpecialWantedcategories.php @@ -29,6 +29,7 @@ * @ingroup SpecialPage */ class WantedCategoriesPage extends WantedQueryPage { + private $currentCategoryCounts; function __construct( $name = 'Wantedcategories' ) { parent::__construct( $name ); @@ -48,6 +49,37 @@ class WantedCategoriesPage extends WantedQueryPage { ); } + function preprocessResults( $db, $res ) { + parent::preprocessResults( $db, $res ); + + $this->currentCategoryCounts = array(); + + if ( !$res->numRows() || !$this->isCached() ) { + return; + } + + // Fetch (hopefully) up-to-date numbers of pages in each category. + // This should be fast enough as we limit the list to a reasonable length. + + $allCategories = array(); + foreach ( $res as $row ) { + $allCategories[] = $row->title; + } + + $categoryRes = $db->select( + 'category', + array( 'cat_title', 'cat_pages' ), + array( 'cat_title' => $allCategories ), + __METHOD__ + ); + foreach ( $categoryRes as $row ) { + $this->currentCategoryCounts[ $row->cat_title ] = $row->cat_pages; + } + + // Back to start for display + $res->seek( 0 ); + } + /** * @param Skin $skin * @param object $result Result row @@ -59,17 +91,37 @@ class WantedCategoriesPage extends WantedQueryPage { $nt = Title::makeTitle( $result->namespace, $result->title ); $text = htmlspecialchars( $wgContLang->convert( $nt->getText() ) ); - $plink = $this->isCached() ? - Linker::link( $nt, $text ) : - Linker::link( + if ( !$this->isCached() ) { + // We can assume the freshest data + $plink = Linker::link( $nt, $text, array(), array(), array( 'broken' ) ); + $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped(); + } else { + $plink = Linker::link( $nt, $text ); + + $currentValue = isset( $this->currentCategoryCounts[ $result->title ] ) + ? $this->currentCategoryCounts[ $result->title ] + : 0; + + // If the category has been created or emptied since the list was refreshed, strike it + if ( $nt->isKnown() || $currentValue === 0 ) { + $plink = "$plink"; + } + + // Show the current number of category entries if it changed + if ( $currentValue !== $result->value ) { + $nlinks = $this->msg( 'nmemberschanged' ) + ->numParams( $result->value, $currentValue )->escaped(); + } else { + $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped(); + } + } - $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped(); return $this->getLanguage()->specialList( $plink, $nlinks ); } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c5b328bb07..f3e1fb484d 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2685,6 +2685,7 @@ It now redirects to [[$2]].', 'ninterwikis' => '$1 {{PLURAL:$1|interwiki|interwikis}}', 'nlinks' => '$1 {{PLURAL:$1|link|links}}', 'nmembers' => '$1 {{PLURAL:$1|member|members}}', +'nmemberschanged' => '$1 → $2 {{PLURAL:$2|member|members}}', 'nrevisions' => '$1 {{PLURAL:$1|revision|revisions}}', 'nviews' => '$1 {{PLURAL:$1|view|views}}', 'nimagelinks' => 'Used on $1 {{PLURAL:$1|page|pages}}', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 74922a6398..43047361ec 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -4849,6 +4849,7 @@ Parameters: * $1 - the number of interwiki links", 'nlinks' => 'This appears in brackets after each entry on the special page [[Special:MostLinked]]. $1 is the number of wiki links.', 'nmembers' => 'Appears in brackets after each category listed on the special page [[Special:WantedCategories]]. $1 is the number of members of the category.', +'nmemberschanged' => 'Appears in brackets after each category listed on the special page [[Special:WantedCategories]] if the number of pages in the category has changed since the list was last refreshed. $1 is the original number of members of the category, $2 is the current one.', 'nrevisions' => 'Used as link text in [[Special:FewestRevisions]]. The link points to the page history (action=history). diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 4a5145f5c8..aeb9453994 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1743,6 +1743,7 @@ $wgMessageStructure = array( 'ninterwikis', 'nlinks', 'nmembers', + 'nmemberschanged', 'nrevisions', 'nviews', 'nimagelinks', -- 2.20.1